/*
** my_str_to_wordtab.c for  in /exam//rendu/ex_9
**
** Made by gregory gueux
** Login   <gueux_g@epitech.net>
**
** Started on  Sat Oct 27 12:19:41 2012 gregory gueux
** Last update Sun Nov 25 17:35:45 2012 gregory gueux
*/

#include <stdlib.h>

int	countword(char *str)
{
  int	m;
  int	i;

  i = 0;
  m = 1;
  while (str[i])
    {
      if (str[i] == ' ')
	m++;
      i++;
    }
  return (m);
}

char	**my_str_to_wordtab(char *str)
{
  char	**tab;
  int	a;
  int	i;
  int	tmp;
  int	count;

  a = 0;
  i = 0;
  tab = xmalloc(sizeof(*tab) * countword(str) + 1);
  count = countword(str);
  while (str[i])
    {
      while (str[i] == ' ')
      	i++;
      if (str[i] != ' ' && a < count)
      	{
      	  tmp = i;
      	  while (str[i] != ' ')
      	    i++;
      	  str[i] = '\0';
      	  tab[a] = str + tmp;
	  a++;
	}
      i++;
    }
  return (tab);
}
